﻿using StudentLive.DataModel;
using StudentLive.DataModel.HubGroups;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Data;

namespace StudentLive
{
    public class HubItemSelector : DataTemplateSelector
    {
        public DataTemplate Favorite { get; set; }
        public DataTemplate CoursePlan { get; set; }
        public DataTemplate Teacher { get; set; }
        public DataTemplate Student { get; set; }
        public DataTemplate Notification { get; set; }
        public DataTemplate Assignment { get; set; }
        public DataTemplate SharedMaterials { get; set; }



        protected override DataTemplate SelectTemplateCore(object item, DependencyObject container)
        {
            DataItem dataItem = item as DataItem;

            if (dataItem.GetType() == typeof(CoursePlanItem))
            {
                return CoursePlan;
            }
            else if (dataItem.GetType() == typeof(ResourceItem)) // Favorite documents
            {
                return Favorite;
            }
            else if (dataItem.GetType() == typeof(TeacherItem))
            {
                return Teacher;
            }
            else if (dataItem.GetType() == typeof(StudentItem))
            {
                return Student;
            }
            else if (dataItem.GetType() == typeof(NotifcationItem))
            {
                return Notification;
            }
            else if (dataItem.GetType() == typeof(SharedMaterialsItem))
            {
                return SharedMaterials;
            }
            else// if (dataItem.GetType() == typeof(AssignmentItem))
            {
                return Assignment;
            }
        }

    }

    public class LessonPageItemSelector : DataTemplateSelector
    {
        public DataTemplate Lessons { get; set; }
        public DataTemplate Resources { get; set; }

        protected override DataTemplate SelectTemplateCore(object item, DependencyObject container)
        {
            DataItem dataItem = item as DataItem;

            if (dataItem.GetType() == typeof(LessonPlanItem))
            {
                return Lessons;
            }
            else if (dataItem.GetType() == typeof(ResourceItem)) // Favorite documents
            {
                return Resources;
            }
            return base.SelectTemplateCore(item, container);
        }

    }

    public class HubZoomOutItemSelector : DataTemplateSelector
    {
        public DataTemplate Favorite { get; set; }
        public DataTemplate CoursePlan { get; set; }
        public DataTemplate Teacher { get; set; }
        public DataTemplate Student { get; set; }
        public DataTemplate Notification { get; set; }
        public DataTemplate Assignment { get; set; }
        public DataTemplate SharedMaterials { get; set; }



        protected override DataTemplate SelectTemplateCore(object item, DependencyObject container)
        {
            DataItem dataItem = item as DataItem;

            if (dataItem.GetType() == typeof(LessonPlans))
            {
                return CoursePlan;
            }
            else if (dataItem.GetType() == typeof(Favorites)) // Favorite documents
            {
                return Favorite;
            }
            else if (dataItem.GetType() == typeof(Teachers))
            {
                return Teacher;
            }
            else if (dataItem.GetType() == typeof(Students))
            {
                return Student;
            }
            else if (dataItem.GetType() == typeof(Notifications))
            {
                return Notification;
            }
            else if (dataItem.GetType() == typeof(SharedMaterials))
            {
                return SharedMaterials;
            }
            else// if (dataItem.GetType() == typeof(AssignmentItem))
            {
                return Assignment;
            }
        }

    }

    public class HubItemGroupStyleSelector : StyleSelector
    {
        public Style Favorites { get; set; }
        public Style CoursePlans { get; set; }
        public Style Teachers { get; set; }
        public Style Students { get; set; }
        public Style Notifications { get; set; }
        public Style SharedMaterials { get; set; }

        protected override Style SelectStyleCore(object item, DependencyObject container)
        {
            var group = (ICollectionViewGroup)item;
            if (group != null)
            {
                return base.SelectStyleCore(item, container);
                //if (group.Group.GetType() == typeof(Notifications))
                //{
                //    return Notifications;
                //}
                // if (group.Group.GetType() == typeof(Favorites))
                //{
                //    return Favorites;
                //}
                //else if (group.Group.GetType() == typeof(LessonPlans))
                //{
                //    return CoursePlans;
                //}
                //else if (group.Group.GetType() == typeof(SharedMaterials))
                //{
                //    return SharedMaterials;
                //}
                //else if (group.Group.GetType() == typeof(Students))
                //{
                //    return Students;
                //}
                //else if (group.Group.GetType() == typeof(Teachers))
                //{
                //    return Teachers;
                //}
            }
            return base.SelectStyleCore(item, container);
        }

        //protected override GroupStyle SelectGroupStyleCore(object group, uint level)
        //{
        //    ICollectionViewGroup hubGroup = group as ICollectionViewGroup;

        //    //return (GroupStyle)App.Current.Resources["NotificationsGroupStyle"];
            
        //    if (hubGroup == null) return Assignment;

        //    if (hubGroup.Group.GetType() == typeof(LessonPlans))
        //    {
        //        return CoursePlan;
        //    }
        //    else if (hubGroup.Group.GetType() == typeof(Favorites)) // Favorite documents
        //    {
        //        return Favorite;
        //    }
        //    else if (hubGroup.Group.GetType() == typeof(Teachers))
        //    {
        //        return Teacher;
        //    }
        //    else if (hubGroup.Group.GetType() == typeof(Students))
        //    {
        //        return Student;
        //    }
        //    else if (hubGroup.Group.GetType() == typeof(Notifications))
        //    {
        //        GroupStyle style = (GroupStyle)App.Current.Resources["NotificationsGroupStyle"];
        //        return style;
        //    }
        //    else// if (dataItem.GetType() == typeof(AssignmentItem))
        //    {
        //        return Assignment;
        //    }
        //}

    }

}
